class GalleriesController < ApplicationController
  before_filter :protect, :user_id
  def index
    @title= "Vea, cree galerias y cargue sus fotos"
    @galleries = Gallery.find :all, :conditions => ["user_id=?",@user.id]
  end

  def show
    @gallery = Gallery.find(params[:id])
  end

  def new
    @title= "Nueva galeria"
    @gallery = Gallery.new

  end

  def create
    @gallery = Gallery.new(params[:gallery])
    @gallery.user_id = @user.id
    if @gallery.save
      flash[:notice] = "Galeria creada."
      redirect_to @gallery
    else
      render :action => 'new'
    end
  end

  def edit
    @gallery = Gallery.find(params[:id])
  end

  def update
    @gallery = Gallery.find(params[:id])
    if @gallery.update_attributes(params[:gallery])
      flash[:notice] = "Galeria actualizada correctamente."
      redirect_to gallery_url
    else
      render :action => 'edit'
    end
  end

  def destroy
    @gallery = Gallery.find(params[:id])
    @gallery.destroy
    flash[:notice] = "Galeria actualizada correctamente."
    redirect_to galleries_url
  end

  private

  def user_id
    @user = User.find(session[:user_id])
  end
end
